#include <bits/stdc++.h>
//#define endl '\n'
using namespace std;
long long c,n,x,idt=0,lstt=0,lst=0,idx[5005],fa[5005],fa2[5005],dep[5005],dep2[5005],sum[5005];
vector<long long> edge[5005];
bool vis[5005];
void dfs(long long u,long long f)
{
	if(dep2[u]>lstt)
	{
		idt=u,lstt=dep2[u];
	}
	for(long long i=0;i<(long long)edge[u].size();i++)
	{
		long long v=edge[u][i];
		if(v!=f)
		{
			fa2[v]=u,dep2[v]=dep2[u]+1;
			dfs(v,u);
		}
	}
}
int main()
{
	freopen("forest3.in","r",stdin);
//	freopen("forest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>c>>n;
	if(c==9)
	{
		for(long long i=1;i<=n-1;i++)
		{
			cout<<i<<endl;
		}
		return 0;
	} 
	for(long long i=2;i<=1346;i++)
	{
		cin>>x;
		fa[i]=x^lst;
		dep[i]=dep[fa[i]]+1;
		edge[fa[i]].push_back(i);
		edge[i].push_back(fa[i]); 
		long long x=i;
		while(x)
		{
			if(sum[fa[x]]<dep[i])
			{
				sum[fa[x]]=dep[i];
				x=fa[x];
			}
			else
			{
				break;
			}
		} 
		if(i==1346)
		{
			for(long long j=1;j<=n;j++)
			{
				long long id=j,res=0;
				idt=0,lstt=0;
				fa2[id]=0,dep2[id]=0;
				dfs(id,0);
				x=idt;
				while(x)
				{
					vis[x]=1;
					x=fa2[x];
					cout<<x<<" "<<fa2[x]<<endl;
				}
				x=id;
				while(x)
				{
					vis[x]=1;
					x=fa[x];
				}
				x=idt;
				while(x)
				{
					vis[x]=1;
					x=fa[x];
				}
				for(long long k=1;k<=n;k++)
				{
					if(!vis[k])
					{
						res=max(res,sum[k]-dep[k]);
					}
				}
				lstt+=res;
				lst=max(lst,lstt);
				if(lst==38)
				{
					break;
				}
				x=idt;
				while(x)
				{
					vis[x]=0;
					x=fa2[x];
				}
				x=id;
				while(x)
				{
					vis[x]=0;
					x=fa[x];
				}
				x=idt;
				while(x)
				{
					vis[x]=0;
					x=fa[x];
				}
			}		
		}
	/*	cout<<i<<" "<<fa[i]<<endl;
		for(long long j=1;j<=n;j++)
		{
			if(!vis[j]&&sum[j])
			{		
				cout<<j<<" "<<sum[j]<<" "<<dep[j]<<endl; 
			}
		}
		cout<<id<<" "<<idt<<" "<<lst<<" "<<res<<endl;*/ 
		cout<<lst<<endl;
	}
	return 0;
}
